<?php
namespace app\home\controller;
//use Qiniu\Http\Request;
use think\Controller;
use  think\Request;
use  think\Db;

class Seller  extends Controller{
    //我的订单
    public function myorder(Request $request)
    {
        if($request->isGet()){
            return  $this->fetch('my_order');
        }


        if($request->isAjax()){
            $map=[];
            $brand=$request->param("brand");
            $sort=$request->param("sort");
            $page=$request->param("page");

            if($sort!="不限"){
                $map['fenlei']=['=',$sort];
            }
            if( $brand!="不限"){
                $map['weizhi']=['=',$brand];
            }


            if($map){
                $uid = session('uid');
                $res = Db::name("goods")
                    ->page($page,5)
                    ->order('id', 'desc')
                    ->where($map)
                    ->where('shop_uid',$uid)
                    ->select();
                $qiniu_config = cmf_get_option('qiniu');
                // 七牛样式处理
                $q_thumb = "?imageMogr2/auto-orient/thumbnail/!60x120r/gravity/Center/crop/120x120/quality/100/interlace/0";
                foreach ($res as $index => $re) {
                    $res[$index]['thumb'] = $qiniu_config['domain'] . '/' . $re['thumb'] . $q_thumb;
                }

            }
            else{
                $res=Db::name("goods")
                    ->page($page,5)
                    ->order('id', 'desc')
                    ->select();
                $qiniu_config = cmf_get_option('qiniu');
                // 七牛样式处理
                $q_thumb="?imageMogr2/auto-orient/thumbnail/!60x120r/gravity/Center/crop/120x120/quality/100/interlace/0";
                foreach ($res as $index => $re) {
                    $res[$index]['thumb'] = $qiniu_config['domain'] . '/' . $re['thumb'].$q_thumb;

                }
            }

            return json($res);
        }

    }
    public function lists(Request $request){
        $flag=$request->param("flag");
        if($flag==1){
            $res=[["name"=>"不限"],["name"=>"开关"],["name"=>"窗帘"],["name"=>"地板"],["name"=>"门"],["name"=>"油漆"],["name"=>"锁"],["name"=>"插座"],];
            return json($res);
        }
        if($flag==2){
            $res=[["name"=>"不限"],["name"=>"客厅"],["name"=>"厨房"],["name"=>"卧室"],["name"=>"阳台"],["name"=>"浴室"],["name"=>"洗漱台"]];
            return json($res);
        }
    }
    public  function  sousuo(){
        return  $this->fetch('ordersousuo');
    }
    public function search(Request $request)
    {
        if ($request->isAjax()) {
            $page = input('page') ? input('page') : 1;
            $limit = input('limit') ? input('limit') : 10;
            $fenlei = $request->param('shuju');
            if($fenlei){

                $res = Db::name("goods")
                    ->page($page,5)
                    ->order('id', 'desc')
                    ->where([
                        'name'=>['like', '%' . $fenlei . '%','or'],
                        'fenlei'=>['like', '%' . $fenlei . '%']
                    ])
                    ->page($page, $limit)->order('create_time', 'desc')->select();


                if ($res) {
                    $qiniu_config = cmf_get_option('qiniu');
                    // 七牛样式处理
                    $q_thumb = "?imageMogr2/auto-orient/thumbnail/!60x120r/gravity/Center/crop/120x120/quality/100/interlace/0";
                    foreach ($res as $index => $re) {
                        $res[$index]['thumb'] = $qiniu_config['domain'] . '/' . $re['thumb'] . $q_thumb;
                    }
                    return json(['code' => 1, 'msg' => 'ok', 'count' => count($res), 'data' => $res]);
                } if(!$res) {
                    $rr=[];
                    return json(['code' => 1, 'msg' => '暂无数据', 'count' => count($rr), 'data' => $rr]);
                }
            }
        }
    }

}